<?php

namespace Biz\model\activity;

use Biz\pockets\modelTrait\BizModelTrait;

trait BizProjectTrait
{
    use BizModelTrait;

    public static function delStatus(): int
    {
        return self::STATUS_DELETE;
    }

    public static function normalStatus(): int
    {
        return self::STATUS_NORMAL;
    }

    public static function isNormal($status): bool
    {
        return $status == self::STATUS_NORMAL;
    }

    public static function adminList(array $condition = []): array
    {
        $list = self::dataSelect($condition + self::statusCondition());
        return $list ? array_column($list, null, 'id') : [];
    }

    public static function adminNameOptions(array $condition = []): array
    {
        $list = self::dataSelect($condition + self::statusCondition());
        return $list ? array_column($list, 'name', 'id') : [];
    }

    public static function statusTotal(array $condition = []): int
    {
        return intval(self::dataCount(self::statusCondition() + $condition));
    }

    public static function statusDelete($id)
    {
        return self::dataUpdate(['status' => self::STATUS_DELETE], ['id' => $id]);
    }

    public static function statusCondition(): array
    {
        return ['status' => self::STATUS_NORMAL];
    }

    public static function addData(array $data = []): int
    {
        $id = $data['id'] ?? 0;
        unset($data['id']);
        if ($id > 0) {
            $data['updated_at'] = date('Y-m-d H:i:s');
        } else {
            if (empty($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s');
            if (empty($data['status'])) $data['status'] = self::STATUS_NORMAL;
        }
        return $id > 0 ? self::update($data, ['id' => $id])->rowCount() : self::insert($data)->rowcount();
    }
}